

#include "tf_LineReader.h"


using namespace std;


CLineReader::CLineReader(const char fileName[1024])
{
	strcpy(m_fileName,fileName);
}

CLineReader::~CLineReader()
{
}


void CLineReader::GetLineVec(std::vector< std::vector<TfPoint> >&LineVec)
{
	LineVec = m_LineVec;
}
bool CLineReader::Read()
{
    int i =0;
    FILE *fp;
    char line[72];
	double pt[3];
	fpos_t file_loc;
	TfPoint ptTmp;
	float ptF[3];
	
    if ( !(fp = fopen(m_fileName, ("r"))) ) 
	{
		return false;
	}
	
	while( !feof(fp) ) 
	{
		fgets(line, 72, fp) ;
		if ( strstr(line , "LINE" ) != NULL )
		{
			vector<TfPoint> lineTmp;
			while (fgets(line, 1024, fp) != NULL && strstr(line , "LINE" ) == NULL)
			{	
				sscanf(line, "%f%f%f",&ptF[0],&ptF[1],&ptF[2]);
				pt[0] = ptF[0];
				pt[1] = ptF[1];
				pt[2] = ptF[2];
				ptTmp.SetPoint(pt);
				lineTmp.push_back(ptTmp);
				fgetpos(fp, &file_loc);
			}
			m_LineVec.push_back(lineTmp);
			fsetpos(fp, &file_loc);
		}
	}
	
    fclose(fp);
    return true;
}

